#include "psync_internal.hpp"

static luaL_Reg psync_core[] =
{
	{"create_node", luapsync_create_node},
	{"node_host", luapsync_node_host},
	{"node_connect", luapsync_node_connect},
	//{"node_put_section", luapsync_node_put_section},
	LUAN(node_extract_serializer),
	{"node_process", luapsync_node_process},
	//{"node_send_packet_all", luapsync_node_send_packet_all},
	//{"node_next_section", luapsync_node_next_section},
	{"node_next_event", luapsync_node_next_event},
	{"node_disconnect", luapsync_node_disconnect},
	LUAN(node_link_latency),
	LUAN(node_set_accept_connections),
	LUAN(node_link_send_packet),
	LUAN(node_link_time_for_packet),
	{NULL, NULL}
};

static luaL_Reg psync_core_node[] =
{
	{"__gc", luapsync_node_gc},
	{NULL, NULL}
};

int luaopen_psync_core(lua_State* L)
{
	make_metatable(L, &psync_core_node_tag, psync_core_node, 0); // mt
	lua_pushvalue(L, -1); // ... | mt mt
	lua_setfield(L, -2, "__index"); // ... | mt
	lua_pop(L, 1); // data

	luaL_openlib(L, "psync_core", psync_core, 0);

	return 1;
}
